let daySeconds = 24 * 60 * 60

let startWorkSeconds = 0
let endWorkSeconds = daySeconds
let workSeconds = daySeconds
if (workingHours) {
    startWorkSeconds = workingHours.startHours * 60 * 60 + workingHours.startMinutes * 60
    endWorkSeconds = workingHours.endHours * 60 * 60 + workingHours.endMinutes * 60
    workSeconds = endWorkSeconds - startWorkSeconds
}

const newOrderList = [];
for (const order of orderList) {
    const startTime = order.startTime
    const endTime = order.endTime

    const startDetail = getTimeDetail(startTime)
    const endDetail = getTimeDetail(endTime)

    const showStartSeconds = getShowSeconds(startDetail.seconds)
    const showEndSeconds = getShowSeconds(endDetail.seconds)
    const x = startDetail.day * colWidth + showStartSeconds / workSeconds * colWidth - 1
    const y = deptOffset[order.dept_id] * rowHeight + 3;
    const width = (showEndSeconds - showStartSeconds + (endDetail.day - startDetail.day) * workSeconds) / workSeconds * colWidth + 1;

    newOrderList.push({
        ...order,
        x: x,
        y: y,
        width: width,
        height: rowHeight - 5,
    });
}

function getShowSeconds(seconds) {
    return Math.min(Math.max(seconds - startWorkSeconds, 0), endWorkSeconds - startWorkSeconds)
}

function getTimeDetail(time) {
    const timeOffset = (time - todayTime + dayTimeOffset)
    const day = Math.floor(timeOffset / daySeconds)
    const seconds = timeOffset % daySeconds
    return { day, seconds }
}

return {
    newOrderList: newOrderList,
};